home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / network / ka9q / ka9q_src.arc / ST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-02  |  17.5 KB  |  855 lines

  1. /* OS- and machine-dependent stuff for Atari-ST
  2.  * Adapted from the PC version to compile under Lattice C
  3.  * by Walter Doerr, DG2KK (dg2kk@cup.portal.com)
  4.  *
  5.  * 20-2-88:    added code from the Atari MWC version by Rob Janssen PE1CHL 
  6.  * 13-1-88:    added code needed for the 871225.1 version
  7.  * 24-12-87:    first version, adapted from PC.C from the 870412 release
  8.  */
  9.  
  10. #include "stdio.h"
  11. #include "global.h"
  12. #include "config.h"
  13. #include "mbuf.h"
  14. #include "internet.h"
  15. #include "iface.h"
  16. #include "st.h"
  17. #include "cmdparse.h"
  18.  
  19. /* #include "stdlib.h"    chkml() , malloc , free */
  20.  
  21. #ifdef LATTICE
  22. #include "dos.h"    /* dfind */
  23. #endif
  24. #include "osbind.h"
  25.  
  26. #ifdef    MWC
  27. #include <stat.h>
  28. FILE *stdprt;
  29. extern    char **environ;
  30. #endif
  31.  
  32. #define TRUE -1
  33. #define FALSE 0
  34.  
  35. struct asy asy[ASY_MAX];
  36.  
  37. /* Interface list header */
  38. struct interface *ifaces;
  39.  
  40. unsigned nasy;            /* needed in v871225.1 */
  41.  
  42. char *ttbuf;
  43. char *rsbuf;            /* location of memory alloc'd for rs232 buf */
  44.  
  45. #ifdef SCREEN
  46. char *newscreen, *newscradr;    /* 32k memory allocated to 2nd video screen */
  47. long logscreen, physcreen;
  48. int toggle = 0;            /* toggle between normal and trace screen */
  49. int printtrace = 0;        /* send trace to printer (controlled by F2) */
  50. #endif
  51.  
  52. char *shell,*getenv();        /* Name of command shell for exec */
  53. int    rows=25;        /* Number of text rows on screen (may be 50) */
  54.  
  55. /* called during init b4 anything is printed on the screen.
  56.  * PC.C does a lot of memory allocation stuff here.
  57.  * We just set the cursor to "blink" and allocate memory for a second video
  58.  * screen.
  59.  */
  60. ioinit()
  61. {
  62.     char *lmalloc();    /* Takes a long arg */
  63.     unsigned long ptr;
  64.  
  65. #ifdef SCREEN
  66.     newscradr = lmalloc(32*1024L);    /* allocate 32k for 2nd video screen */
  67.     ptr = (unsigned long)newscradr;
  68.     newscreen = (char *)((ptr+255) & 0xffffff00L);    /* 256 byte boundary */
  69.  
  70.     physcreen = (long)Physbase();    /* remember displayed screen address */
  71.     logscreen = (long)Logbase();    /* remember output screen address */
  72.     Cconws("\033j");        /* Save cursor position */
  73.     (void) Setscreen(newscreen,-1L,-1);    /* switch to 2nd screen */
  74.     (void) Vsync();            /* wait for vsync */
  75.     Cconws("\033H\033J");        /* cursor home, clear screen */
  76.     Cconws("\033k");        /* restore cursor position */
  77.     (void) Setscreen(logscreen,-1L,-1);    /* restore old screen */
  78.     (void) Vsync();            /* wait for vsync */
  79. #endif
  80.     printf("\033v\033e\n");        /* Autowrap on, Cursor on */
  81.     (void) Cursconf(2,0);        /* make the cursor blink (3=steady) */
  82. #ifdef MWC
  83.     stdprt = fopen("prn:","w");
  84. #endif
  85.  
  86.     shell = getenv("NROWS");
  87.     if (shell != NULL)
  88.         rows=atoi(shell);
  89.  
  90.     shell = getenv("SHELL");
  91.     if (shell == NULL)
  92.         shell="\\bin\\gulam.prg";
  93. }
  94.  
  95. /* Called just before exiting. 
  96.  * delete temp files.
  97.  * free memory allocated to the rs-232 and midi buffers.
  98.  */
  99. iostop()
  100. {
  101.     /* free memory allocated to 2nd video screen */
  102.  
  103. #ifdef SCREEN
  104.     dispscreen(0);        /* switch back to original screen */
  105.     free(newscradr);
  106. #endif
  107.  
  108.     /* delete all temp files that have accumulated */
  109.     (void) tmpdel();
  110.  
  111.     /* free memory allocated to RS-232/MIDI I/O buffers */
  112.     while (ifaces != NULLIF) {
  113.         if (ifaces->stop != NULLFP)
  114.             (*ifaces->stop)(ifaces);
  115.         ifaces = ifaces->next;
  116.     }
  117.  
  118.     printf("\n");
  119. }
  120.  
  121.  
  122. /* checks the time then ticks and updates ISS */
  123. static int32 clkval = 0;
  124. void
  125. check_time()
  126. {
  127.     int32 iss();            /* initial sequence number */
  128.     int32 clksec();
  129.     if(clkval != clksec()){
  130.          clkval = clksec();
  131.         icmpclk();
  132.         tick();
  133.         (void)iss();
  134.     }
  135. }
  136.  
  137. /* returns the number of seconds from system clock */
  138. static int32
  139. clksec()
  140. {
  141.     long tloc;
  142.     time(&tloc);
  143.     return (tloc);
  144. }
  145.  
  146.  
  147. /* Initialize async port "dev" (adapted from PE1CHL) */
  148. int
  149. asy_init(dev,bufsize)
  150. int16 dev;
  151. unsigned bufsize;
  152. {
  153.     register struct iorec *ip;
  154.     register struct asy *ap;
  155.     char *bufp;
  156. /*    char i_state; */
  157.  
  158. #ifdef DEBUG
  159.     printf("asy_init: dev=%d bufsize=%d\n",dev,bufsize);
  160.     fflush(stdout);
  161. #endif
  162.     ap = &asy[dev];
  163.  
  164.     if (ap->addr != RS232 && ap->addr != MIDI) {
  165.         printf("asy_init(%d): unknown interface\n",dev);
  166.         return -1;
  167.     }
  168.  
  169.     /* force user to allocate more memory than he already has.
  170.      * If no memory is allocated, asy_stop() may behave funny...
  171.      */
  172.     if (bufsize <= 256)    /* only allocate a bigger buffer */
  173.         return -1;
  174.  
  175.     if ((bufp = malloc(bufsize)) == NULLCHAR){
  176.         printf("asy_init(%d): no memory for rx buffer\n",dev);
  177.         return -1;
  178.     }
  179.  
  180.     /* Save original IOREC values */
  181.  
  182.     ip = Iorec((ap->addr)-1);    /* Iorec wants AUX: = 0, MIDI = 2 */
  183.  
  184.     Jdisint(12);            /* disable RS-232 interrupt */
  185.  
  186.     ap->in = ip;
  187.     memcpy(&ap->oldin,ip);
  188.     if (ap->addr == RS232) {    /* increase RS-232 transmit buffer? */
  189.         ip++;
  190.         ap->out = ip;
  191.         memcpy(&ap->oldout,ip);
  192.     }
  193.  
  194.     /* Set up receiver FIFO */
  195.     ap->in->ibuf = bufp;
  196.     ap->in->ibufsiz = bufsize;
  197.     ap->in->ibufhd = ap->in->ibuftl = 0;
  198.     ap->in->ibuflow = 0;
  199.     ap->in->ibufhi = bufsize;
  200.  
  201.     if (ap->addr == RS232) {
  202.         /* clear transmitter FIFO */
  203.         ap->out->ibufhd = ap->out->ibuftl = 0;
  204.         ap->out->ibuflow = 0;
  205.         ap->out->ibufhi = ap->out->ibufsiz;
  206.     }
  207.  
  208.     Jenabint(12);            /* enable RS-232 interrupts */
  209.  
  210.     if (ap->addr == RS232)
  211.         Rsconf(-1,0,-1,0,0,0);    /* 8 bits, no parity */
  212.  
  213. #ifdef DEBUG
  214.     printf("asy_init: Iorecs in: 0x%lx out: 0x%lx\n",ap->in,ap->out);
  215.     printf("    inbuf: 0x%lx outbuf: 0x%lx\n",ap->in->ibuf,
  216.         ap->out->ibuf);
  217. #endif
  218. }
  219.  
  220.  
  221. /* asy_stop restores old iorec and frees memory allocated to the RS-232/MIDI
  222.  * buffers. (from PE1CHL)
  223.  */
  224. int
  225. asy_stop(iface)
  226. struct interface *iface;
  227. {
  228.     register struct asy *ap;
  229. /*    char i_state; */
  230.  
  231. #ifdef DEBUG
  232.     printf("asy_stop: iface=0x%lx dev=%d\n",iface,iface->dev);
  233.     fflush(stdout);
  234. #endif
  235.     ap = &asy[iface->dev];
  236.  
  237.     (void) Jdisint(12);        /* disable RS-232 interrupts */
  238.  
  239.     free(ap->in->ibuf);        /* free the buffer */
  240.  
  241.     /* Restore old iorecs */
  242.     memcpy(ap->in,&ap->oldin,sizeof(struct iorec));
  243.     if (ap->addr == RS232)
  244.         memcpy(ap->out,&ap->oldout,sizeof(struct iorec));
  245.  
  246.     (void) Jenabint(12);        /* enable RS-232 interrupts */ 
  247. }
  248.  
  249.  
  250. /* Set async line speed */
  251. int
  252. asy_speed(dev,speed)
  253. int dev;
  254. int speed;
  255. {
  256.     int baud; /* int result; */
  257.     register int sp;
  258.     long sav_ssp;
  259.  
  260.     if (speed <= 0 || dev >= nasy)
  261.         return -1;
  262.  
  263.     asy[dev].speed = speed;        /* shouldn't this be done in slip.c? */
  264.  
  265.     switch (asy[dev].addr) {
  266.  
  267.     case RS232:
  268.         switch (speed) {
  269.         case 300:
  270.             baud = 9;    /* how slow can you get? :-) */
  271.             break;
  272.         case 1200:
  273.             baud = 7;
  274.             break;
  275.         case 2400:
  276.             baud = 4;
  277.             break;
  278.         case 4800:
  279.             baud = 2;
  280.             break;
  281.         case 9600:
  282.             baud = 1;
  283.             break;
  284.         case 19200:
  285.             baud = 0;
  286.             break;
  287.         default:
  288.             printf("asy_speed: unknown RS-232 speed (%d).\n",speed);
  289.             return -1;
  290.         }
  291.         (void) Rsconf(baud,0,0x88,-1,-1,-1);    /* no flow control */
  292.         break;
  293.  
  294.     case MIDI:
  295.         /* midi can run on 500000 or 614400Hz clock (hardware mod)
  296.          */
  297.         switch (speed)
  298.         {
  299.         case 0x9600:        /* = 38400 unsigned... (hardware mod) */
  300.         case 31250:        /* normal MIDI baudrate */
  301.             sp = 0x95;    /* /16 */
  302.             break;
  303.  
  304.         case 9600:        /* 9600 Baud requires hardware mod */
  305.         case 7812:        /* 7812 Baud on an unmodified Atari */
  306.             sp = 0x96;    /* /64 */
  307.             break;
  308.  
  309.         default:
  310.             printf("asy_speed: unknown MIDI speed (%d).\n",speed);
  311.             return -1;
  312.         }
  313.  
  314.         sav_ssp = Super(NULL);        /* switch to Supervisor mode */
  315.         *((char *) 0xfffffc04L) = 0x03; /* Reset 6850 */
  316.         hiword(0);            /* spend some time */
  317.         *((char *) 0xfffffc04L) = sp;    /* set new divider ratio */
  318.         Super(sav_ssp);            /* back to User mode */
  319.  
  320.         break;
  321.     }
  322.     asy_flush(dev);
  323. }
  324.  
  325.  
  326. /* flush the input buffer of device dev (either aux: or midi).
  327.  * May be useful, because setting the baudrate causes an 0x7f to be sent.
  328.  */
  329. asy_flush(dev)
  330. int dev;
  331. {
  332.     int st_dev;
  333.     long c;                    /* Bconin returns a long */
  334.     st_dev = asy[dev].addr;
  335.  
  336.     while (Bconstat(st_dev) == -1) {    /* at least 1 char avlb */
  337.         c = Bconin(st_dev);
  338.     }
  339. }
  340.  
  341.  
  342. /* Send a buffer to serial transmitter */
  343. asy_output(dev,buf,cnt)
  344. unsigned dev;
  345. char *buf;
  346. unsigned short cnt;
  347. {
  348.     int st_dev; /* int c; */
  349.     unsigned short i = 0;
  350.  
  351.     if (dev >= nasy)
  352.         return -1;
  353.  
  354.     st_dev = asy[dev].addr;
  355.     for (i = 0 ; i < cnt ; ++i) {
  356.         (void)Bconout(st_dev,buf[i]);    /* 1= AUX: 3=MIDI: */
  357.     }
  358. }
  359.  
  360.  
  361. /* Receive characters from async line
  362.  * Returns count of characters received
  363.  * dev is the device 
  364.  * buf is the buffer where received characters are stored
  365.  * cnt is the number of characters the calling routine expects to find in buf.
  366.  * On return, the no of chars still in the rs-232 buffer should be returned!??
  367.  * Quick and dirty hack: 
  368.  * since this routine is called from one location (slip.c) only, with cnt=1
  369.  * we just return the AUX: state (char avlb or not (bios(1,1) bconstat)).
  370.  * 
  371.  */
  372. unsigned
  373. asy_recv(dev,buf,cnt)
  374. int dev;
  375. char *buf;
  376. unsigned cnt;
  377. {
  378.     char c;
  379.     int rs_state;
  380.     int st_dev = asy[dev].addr;    /* AUX: device on the Atari ST */
  381.     int snd_dev = asy[dev].vec;
  382.  
  383.     rs_state = Bconstat(st_dev);    /* 0 = no char, -1 = char avlb */
  384.  
  385.     if (rs_state == -1) {
  386.         rs_state = 1;        /* at least one char available */
  387.         c = (char)Bconin(st_dev);
  388.  
  389.         /* this does the actual retransmitting of received bytes
  390.          * depending on the vector field in the 'attach asy' command.
  391.          * remove it, if you don't have use for it.
  392.          */
  393.         if (snd_dev == 1 || snd_dev == 3) {    /* if AUX: or MIDI */
  394.             (void)Bconout(snd_dev,c & 0xff);
  395.         }
  396.         *buf = c & 0xff;
  397.     }
  398.     return (rs_state);    /* 0 = no char, 1 = at least 1 more char */
  399. }
  400.  
  401. #ifdef    MWC
  402. int                /* Just for argument's sake... -- hyc */
  403. kbhit()
  404. {
  405.     return(Bconstat(2));
  406. }
  407. #endif
  408.  
  409. int kbread()
  410. {
  411.     int c;
  412.     long    raw;
  413.  
  414.     if (kbhit() == 0)    /* no key hit: just return */
  415.         return (-1);
  416.  
  417.     raw = Bconin(2);    /* Read ASCII and scan code from keyboard */
  418.     c = raw & 0x7f;        /* get rid of scan codes !!!! */
  419.  
  420. #ifdef    ESCAPEOUT        /* Why would you *ever* do this???  -- hyc */
  421.     if (c == 0x1b)
  422.         c = -2;        /* ESCAPE behaves like F10 */
  423. #endif
  424.     /* process function keys */
  425.     if (c == 0) {        /* we have an F key */
  426.         switch((int) ((raw >> 16) & 0xff)) {
  427.         case 0x3b:            /* F1 */
  428.             toggle = ~toggle;
  429.             (void) dispscreen(toggle);
  430.             c = -1;
  431.             break;
  432.  
  433.         case 0x3c:            /* F2 */
  434.             printtrace = 0;        /* printer off */
  435.             c = -1;
  436.             break;
  437.  
  438.         case 0x55:            /* Shift F2 */
  439.             printtrace = 1;        /* printer on */
  440.             c = -1;
  441.             break;
  442.  
  443.         case 0x44:            /* F10 */
  444.             c = -2;
  445.             break;
  446.         default:
  447.             c = -1;            /* ignore other keys */
  448.             break;
  449.         }
  450.     }
  451.     return (c);
  452. }
  453.  
  454.  
  455. /* Create a temporary file and return the filepointer
  456.  * (adapted from the routine in mac_io.c)
  457.  */
  458. FILE *
  459. tmpfile()
  460. {
  461.     FILE *tmp;
  462.     char name[20];
  463.     long tt;
  464.  
  465.     tt = clksec();
  466.     tt &= 0x007fffffL;
  467.     sprintf(name,"\\X%07.7ld.tmp",tt);
  468.  
  469. #ifdef DEBUG
  470.     printf("tmpfile: create file %s\n",name);
  471. #endif
  472.     if ((tmp = fopen(name,"wb+")) == NULL) {
  473.         printf("tmpfile: could not create temp file. (%s)\n",name);
  474.         return (NULL);
  475.     }
  476.     return (tmp);
  477. }
  478.  
  479.  
  480. int disable()
  481. {
  482.     return 1;
  483. }
  484.  
  485. void eihalt()
  486. {
  487. }
  488.  
  489.  
  490. /* the following is new stuff from version 871225.1 */
  491.  
  492. asy_ioctl(interface,argc,argv)
  493. struct interface *interface;
  494. int argc;
  495. char * argv[];
  496. {
  497.     if (argc < 1) {
  498.         printf("speed: %d baud\n",asy[interface->dev].speed);
  499.         return 0;
  500.     }
  501.     return asy_speed(interface->dev,atoi(argv[0]));
  502. }
  503.  
  504. int asy_rxint()
  505. {
  506.     printf("asy_rxint\n");
  507. }
  508.  
  509. int asy_txint()
  510. {
  511.     printf("asy_txint\n");
  512. }
  513.  
  514. int setbit()
  515. {
  516.     printf("setbit\n");
  517. }
  518.  
  519. int clrbit()
  520. {
  521.     printf("clrbit\n");
  522. }
  523.  
  524. void
  525. rename(s,d)
  526.     char *s, *d;        /* Source and dest name */
  527. {
  528.     Frename(0, s, d);    /* Ignore return code... */
  529. }
  530.  
  531. doshell()
  532. {
  533.     long execstat;
  534.     char *args[2];
  535.  
  536. #ifdef SCREEN
  537.     /* make sure that we are on the right (main) screen */
  538.     dispscreen(0);
  539.     toggle = 0;
  540. #endif
  541.     args[0]="shell";
  542.     args[1]=NULL;
  543.     execstat = exec(shell,args);
  544.  
  545.     if (execstat != 0)
  546.         printf("Pexec: errorcode: %ld\n",execstat);
  547.  
  548.     printf("\n");
  549.     (void)Cursconf(1,0);        /* cursor on */
  550.     (void)Cursconf(2,0);        /* cursor blink */
  551. }
  552.  
  553.  
  554. dotype(argc,argv)
  555. int argc;
  556. char *argv[];
  557. {
  558.     char tstring[200];
  559.     char fname[50];
  560.     FILE *tfile;
  561.     int linecnt = 0;
  562.  
  563.     if (argc != 2) {
  564.         printf("Usage: type <filename>\n");
  565.         return;
  566.     }
  567.  
  568.     strcpy(fname,argv[1]);
  569.     if ((tfile = fopen(fname, "r")) == NULLFILE) {
  570.         printf("type: cannot open '%s'\n",fname);
  571.         return;
  572.     }
  573.  
  574.     while (!feof(tfile)) {
  575.         fgets(tstring,200,tfile);
  576.         linecnt++;
  577.         if (strlen(tstring) > 79)
  578.             linecnt++;
  579.         printf("%s",tstring);
  580.         if ((linecnt % 23) == 0) {
  581.             printf("\033p more \033q");
  582.             if ((gemdos(7) & 0x7f) == 'q') {
  583.                 printf("\033l\n");
  584.                 break;
  585.             }
  586.             printf("\033l");
  587.         }
  588.     }
  589.     fclose(tfile);
  590. }
  591.  
  592. int restore(istate)
  593. int istate;
  594. {
  595. }
  596.  
  597. giveup()
  598. {
  599. }
  600.  
  601.  
  602. int stxrdy(dev)
  603. int dev;
  604. {
  605.     int stat;
  606.     int st_dev;
  607.  
  608.     st_dev = asy[dev].addr;
  609.     stat=(int)Bcostat(st_dev);    /* Bcostat:  -1 ready , 0 not ready */
  610.     if (stat == -1) {
  611.         stat = 1;
  612.     }
  613.     return (stat);
  614. }
  615.  
  616. #ifdef    LATTICE
  617. /*
  618.  * replacement for buggy Lattice memchr function used in telnet.c
  619.  */
  620. char *
  621. memchr_st(str,c,n)
  622. char *str;
  623. char c;
  624. unsigned n;
  625. {
  626.     while (n-- != 0) {
  627.         if (*str++ == c)
  628.             return (str);
  629.     }
  630.     return NULLCHAR;
  631. }
  632.  
  633.  
  634. /* move (copy) a block of memory */
  635. /* this function assumes the blocks do not overlap */
  636. memcpy (d,s,c)
  637. register char *d;            /* destination pointer */
  638. register char *s;            /* source pointer */
  639. register int  c;            /* bytecount */
  640. {
  641.     if (c)                /* nonzero count? */
  642.     do
  643.     {
  644.         *d++ = *s++;        /* then move on */
  645.     } while (--c);            /* while more to go */
  646. }
  647.  
  648. /* fill a block of memory */
  649. void memset (p,c,n)
  650. register char *p;            /* block pointer */
  651. register char c;            /* initialization value */
  652. register int  n;            /* bytecount */
  653. {
  654.     if (n)                /* nonzero count? */
  655.     do
  656.     {
  657.         *p++ = c;        /* then do it */
  658.     } while (--n);            /* more to fill? */
  659. }
  660.  
  661. /* compare memory blocks, return 0 if equal */
  662. int memcmp (d,s,c)
  663. register char *d;            /* destination pointer */
  664. register char *s;            /* source pointer */
  665. register int  c;            /* bytecount */
  666. {
  667.     if (c)                /* nonzero count? */
  668.     do
  669.     {
  670.         if (*s++ != *d++)    /* compare */
  671.         return (*--d - *--s);    /* when unequal, return diff */
  672.     } while (--c);            /* while more to go */
  673.  
  674.     return (0);                /* equal! */
  675. }
  676.  
  677. /* lookup some character in a memory block */
  678. char *memchr (p,c,n)
  679. register char *p;            /* block pointer */
  680. register char c;            /* value to look for */
  681. register int  n;            /* bytecount */
  682. {
  683.     while (n--)
  684.     if (*p == c)
  685.         return (p);
  686.     else
  687.         p++;
  688.  
  689.     return (NULLCHAR);
  690. }
  691. #endif    /* LATTICE */
  692.  
  693. memstat()
  694. {
  695. #ifdef    AX25
  696.     extern int digisent;
  697. #endif
  698.     long size;
  699.  
  700.     size = Malloc(-1L);
  701.     printf("\nFree memory: %ld bytes.\n\n",size);
  702. #ifdef    AX25
  703.     printf("Digisent: %d frames.\n\n",digisent);
  704. #endif
  705.     printf("AUX:");
  706.     iosize(0);
  707.     printf("MIDI:");
  708.     iosize(2);
  709. }
  710.  
  711. iosize(i)
  712. int i;
  713. {
  714.     struct iorec *rsbuffer;
  715.  
  716.     rsbuffer = (struct iorec*) Iorec(i);        /* get iorec */
  717.     printf("\tIorec:  %08lx\n",rsbuffer);
  718.     printf("\tBuffer: %08x\n",rsbuffer->ibuf);
  719.     printf("\tSize:   %d bytes\n",rsbuffer->ibufsiz);
  720. }
  721.  
  722. #ifdef    LATTICE
  723. #define    DMABUFFER    struct FILEINFO
  724. #define d_fname        name
  725. #endif
  726.  
  727. /* delete all temp files which have accumulated */
  728. tmpdel()
  729. {
  730.     DMABUFFER info;
  731.     char delnam[20];
  732.     int error;
  733.  
  734.     Fsetdta(&info);
  735.  
  736.     if ((error = Fsfirst("\\x*.tmp",0)) != 0){
  737.         info.d_fname[0] = '\0';
  738.     }
  739.     while (info.d_fname[0] != '\0') {
  740.         sprintf(delnam,"\\%s",info.d_fname);
  741.         unlink(delnam);
  742.         if ((error = Fsnext()) != 0) {
  743.             info.d_fname[0] = '\0';
  744.         }
  745.     }
  746. }
  747.  
  748. #ifdef    LATTICE        /* The MWC version seems OK. -- hyc */
  749. /* the access() call doesn't seem to work in Lattice-C.
  750.  * this is a quick and dirty hack...
  751.  * it returns -1 if the file exists and 0 if it doesn't.
  752.  */
  753. int
  754. access(name,mode)
  755. char *name;
  756. int mode;
  757. {
  758.     struct FILEINFO *info;
  759.     int ret;
  760.  
  761.     Fsetdta(&info);
  762. /*printf("access: name='%s' mode=%d\n",name, mode);*/
  763.     if ((ret = Fsfirst(name,0)) != 0)
  764.         return -1;
  765. /*printf("access: return 0 (file exists)\n");*/
  766.     return 0;
  767. }
  768. #endif
  769.  
  770. #ifdef SCREEN
  771.  
  772. /* dispscreen selects the screen to be displayed by the video hardware.
  773.  * this routine is called from within kbread()
  774.  * flag:  =0: display normal screen
  775.  *       <>0: display trace screen
  776.  */
  777. dispscreen(flag)
  778. int flag;
  779. {
  780.     if (flag == 0) {
  781.         (void) Setscreen(-1L,physcreen,-1);
  782.         (void) Vsync();
  783.         printf("\033e");    /* turn on cursor */
  784.     } else {
  785.         (void) Setscreen(-1L,newscreen,-1);
  786.         (void) Vsync();
  787.         printf("\033f");    /* turn off cursor */
  788.     }
  789. }
  790.  
  791.  
  792. /* outscreen selects one of two screens where display output (printf's) should
  793.  * go to.
  794.  * outscreen is called from trace.c before/after trace output is done
  795.  */
  796. outscreen(flag)
  797. int flag;
  798. {
  799.     if (flag == 0) {
  800.         (void) Setscreen(logscreen,-1L,-1);
  801.         (void) Vsync();
  802.         printf("\033k");    /* restore cursor pos on main screen */
  803.     } else {
  804.         (void) Setscreen(newscreen,-1L,-1);
  805.         (void) Vsync();
  806.         printf("\033j");    /* save cursor pos on main screen */
  807.         printf("\033Y%c%c",rows+31,32);
  808.     }
  809. }
  810. #endif
  811.  
  812. #ifdef    MWC
  813.  
  814. static exec(command,args)
  815. char *command;
  816. char *args[];
  817. {
  818.     char **envx;
  819.     register int i,j,k,l;
  820.  
  821.     j=(-1);
  822.     for(i=0;environ[i]!=0;i++)    /* Count vars in environment */
  823.         if(!strncmp(environ[i],"ARGV",4))    /* Skip ARGV */
  824.             j=i;
  825.  
  826.     if(j<0)
  827.         i++;
  828.  
  829.     envx=(char **)malloc(i*sizeof(char *));    /* Copy environment */
  830.     i--;
  831.     envx[i] = NULL;
  832.  
  833.     for(k=0,l=0;k<i;l++)
  834.         if(l!=j) {
  835.             envx[k]=malloc(strlen(environ[l])+1);
  836.             strcpy(envx[k],environ[l]);
  837.             k++;
  838.         }
  839.     
  840.     return(execve(command,args,envx));
  841. }
  842. #endif
  843.     
  844. /* Do a warm boot, I think. -- hyc */
  845. void
  846. sysreset()
  847. {
  848.     long *resvec,(*resjump)(),newstack[16];
  849.  
  850.     Super(newstack);    /* Get into supervisor mode to read sys vars */
  851.     resvec = (long *)0x42a;
  852.     resjump = *resvec;
  853.     (*resjump)();
  854. }
  855.